<html>
<head><meta charset="utf-8"><title>Unix Mutex `Send` · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html">Unix Mutex `Send`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="165450652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165450652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lee Mracek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165450652">(May 12 2019 at 06:30)</a>:</h4>
<p>I'm not clear on why <a href="https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/mutex.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/mutex.rs">https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/mutex.rs</a> is <code>Send</code>. My understanding is that an ownership transfer to a different thread involves a move and pthread mutexes cannot be moved.</p>



<a name="165460567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165460567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Gilcher <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165460567">(May 12 2019 at 11:21)</a>:</h4>
<p>It moves the pointer to the mutex, not the mutex itself.</p>



<a name="165483858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165483858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lee Mracek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165483858">(May 12 2019 at 22:11)</a>:</h4>
<p>Not in the unix implementation? It's just an <code>UnsafeCell</code> wrapping a <code>pthread_mutex_t</code> which is typically just a struct.</p>
<p>I expect <code>::std::sync::Mutex</code> to be sync and send since it's in a <code>Box</code>, but the internal implementation isn't.</p>



<a name="165515580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165515580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165515580">(May 13 2019 at 10:27)</a>:</h4>
<p>the internal <code>Mutex</code> is <code>Send</code> but not movable... it's a bit weird, but e.g. <code>&amp;mut Mutex</code> is fine to <code>Send</code>.</p>



<a name="165515630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165515630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165515630">(May 13 2019 at 10:28)</a>:</h4>
<p>making it non-<code>Send</code> wouldnt help with the issues around moving it</p>



<a name="165515634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165515634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165515634">(May 13 2019 at 10:28)</a>:</h4>
<p>but anyway all that will be moot once <a href="https://github.com/rust-lang/rust/pull/56410" target="_blank" title="https://github.com/rust-lang/rust/pull/56410">https://github.com/rust-lang/rust/pull/56410</a> lands</p>



<a name="165534055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unix%20Mutex%20%60Send%60/near/165534055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lee Mracek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unix.20Mutex.20.60Send.60.html#165534055">(May 13 2019 at 14:35)</a>:</h4>
<p>Ooo yup hadn't seen that PR</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>